'use server'

import { prisma } from '@/lib/prisma'
import { revalidatePath } from 'next/cache'

export async function createEmployee(data: any) {
  const employee = await prisma.employee.create({
    data: {
      name: data.name,
      phone: data.phone,
      position: data.position,
      department: data.department,
      status: true
    }
  })

  revalidatePath('/dashboard/employees')
  return employee
}

export async function updateEmployee(id: number, data: any) {
  const employee = await prisma.employee.update({
    where: { id },
    data: {
      name: data.name,
      phone: data.phone,
      position: data.position,
      department: data.department,
      status: data.status
    }
  })

  revalidatePath('/dashboard/employees')
  return employee
}

export async function deleteEmployee(id: number) {
  const employee = await prisma.employee.delete({
    where: { id }
  })

  revalidatePath('/dashboard/employees')
  return employee
} 